package org.example.demo1startjava17.filter;

import jakarta.servlet.Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置方式3
 * 2.配置类中指定FilterRegistrationBean过滤器相关信息：类型，顺序，路径等
 * // TODO 如果设置了context-path，实际拦截的请求是 /context-path/{以下的url}，假如context-path=1，则实际被过滤的请求是 /1/1/test/* vash
 */
@Configuration
public class MyFilter3Config {

    @Bean
    public FilterRegistrationBean filter3Bean() {
        FilterRegistrationBean<Filter> filterFilterRegistrationBean = new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setFilter(new MyFilter3());
        filterFilterRegistrationBean.setOrder(2);//执行的顺序
        filterFilterRegistrationBean.addUrlPatterns("/*");
        return filterFilterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean filter4Bean() {
        FilterRegistrationBean<Filter> filterFilterRegistrationBean = new FilterRegistrationBean<>();
        filterFilterRegistrationBean.setFilter(new MyFilter4());
        filterFilterRegistrationBean.setOrder(1);//执行的顺序
        // TODO 如果设置了context-path，实际拦截的请求是 /context-path/{以下的url}，假如context-path=1，则实际被过滤的请求是 /1/1/test/* vash
        filterFilterRegistrationBean.addUrlPatterns("/1/test/*");
        return filterFilterRegistrationBean;
    }
}